package weifei.mall.entity;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.springframework.stereotype.Repository;

import java.util.Date;




/**
 *
 * -- 订单表
 * CREATE TABLE orders
 * (
 *     id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
 *     goods_id BIGINT UNSIGNED NOT NULL COMMENT "商品ID",
 *     specification_id BIGINT UNSIGNED DEFAULT NULL COMMENT "规格ID",
 *     buyer_id INT UNSIGNED NOT NULL COMMENT "买家用户ID",
 *     seller_id INT UNSIGNED NOT NULL COMMENT "卖家用户ID",
 *     address_id BIGINT UNSIGNED NOT NULL COMMENT "收获地址ID",
 *     count INT UNSIGNED DEFAULT 1 NOT NULL COMMENT "购买数量",
 *     create_time DATETIME DEFAULT NOW(),
 *     state TINYINT UNSIGNED DEFAULT 1 NOT NULL,          -- 1 is WaitingForPayment
 *     tracking_number TEXT DEFAULT NULL,
 *     delivery_time DATETIME DEFAULT NULL,
 *     PRIMARY KEY (id),
 *     FOREIGN KEY (goods_id) REFERENCES goods(id),
 *     FOREIGN KEY (specification_id) REFERENCES goods_specification(id),
 *     FOREIGN KEY (buyer_id) REFERENCES user(id),
 *     FOREIGN KEY (seller_id) REFERENCES user(id),
 *     FOREIGN KEY (address_id) REFERENCES user_address(id)
 * );
 *
 * */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("orders")
@Repository
public class Orders extends Model<Orders>
{
    @Getter
    public enum Column
    {
        ID("id"),
        GoodsID("goods_id"),
        SpecificationID("specification_id"),
        BuyerID("buyer_id"),
        SellerID("seller_id"),
        AddressID("address_id"),
        Count("count"),
        CreateTime("create_time"),
        State("state"),
        TrackingNumber("tracking_number"),
        DeliveryTime("delivery_time");

        final String name;
        Column(String name) { this.name = name; }
    }


    public enum State
    {
        WaitingForPayment(1),       // 待付款
        WaitingForDelivery(2),      // 待发货
        Delivered(3),               // 已发货
        Finished(4),                // 已完成
        Service(5);                 // 售后

        @EnumValue
        final int id;
        State(int id) { this.id = id; }
    }


    @TableId
    private Integer id;
    private Integer goodsId;
    private Integer specificationId;
    private Integer buyerId;
    private Integer sellerId;
    private Integer addressId;
    private Integer count;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date create_time;
    private State state;
    private String trackingNumber;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date deliveryTime;


    public Orders() {}
    public Orders(int id) { this.id = id; }
}

